<?php

namespace App\Http\Requests\Api;

class ComRegRequest extends ApiRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => 'bail|required|api_check_username',
            'password' => 'required|between:6,60',
            'contacts' => 'required',
            'company_name' => 'required',
            'email' => 'email',
            'mobile' => 'bail|required|mobile_verification',
            'phone' => 'bail|check_company_phone',
            'code' => 'required',
            'wx_code' => 'required_if:type,js_personal,js_company,ios_personal,ios_company,android_personal,android_company',
            'encrypted_data' => 'required_if:type,js_personal,js_company',
            'iv' => 'required_if:type,js_personal,js_company',
            'qq_access_token' => 'required_if:type,ios_qq_personal,ios_qq_company,android_qq_personal,android_qq_company'
        ];
    }

    public function attributes()
    {
        return [
            'username' => '用户名',
            'password' => '密码',
            'mobile' => '手机号码',
            'contacts' => '联系人',
            'company_name' => '公司名称',
            'email' => '邮箱',
            'phone' => '固定电话',
            'code' => '验证码'
        ];
    }

    public function messages()
    {
        return array_merge(parent::messages(), [
            'username.unique' => ':attribute已被注册',
            'password.between' => '密码长度需:min~:max个字',
            'phone.check_company_phone' => '请输入正确的区号和电话号码',
            'mobile.mobile_verification' => '请输入正确的手机号码',
        ]);
    }
}
